package com.itheima.controller;

import com.itheima.pojo.Book;
import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/jsonparam")
public class ParamJsonController {

    @RequestMapping("/json1")
    @ResponseBody
    public String json1(@RequestBody List<String> list) {
        System.out.println(list);
        return "{' info ' : ' ok ~ ~ '}";
    }

    @RequestMapping("/json2")
    @ResponseBody
    public String json2(@RequestBody User user) {
        System.out.println(user);
        return "{' info ' : ' ok ~ ~ '}";
    }

    @RequestMapping("/json3")
    @ResponseBody
    public String json3(@RequestBody List<User> user) {
        System.out.println(user);
        return "{' info ' : ' ok ~ ~ '}";
    }

    @RequestMapping("/r1")
    @ResponseBody
    public String r1() {
        System.out.println("response1");
        return "/html/index.html";
    }

    @RequestMapping("/resp1")
    @ResponseBody
    public User response1() {
        System.out.println("response1");
        User user = new User();
        user.setId(01);
        user.setName("张三");
        user.setAge(18);
        return user;
    }

    @RequestMapping("/resp2")
    @ResponseBody
    public List response2() {
        System.out.println("response2");
        List<User> list = new ArrayList<User>();
        User user = new User();
        user.setId(01);
        user.setName("张三");
        user.setAge(18);
        list.add(user);
        list.add(user);
        list.add(user);
        list.add(user);
        return list;
    }

    @ResponseBody
    @RequestMapping("/resp3")
    public User response3() {
        System.out.println("response3");
        User user = new User(2,"王五",25,new Book());
        return user;
    }

    @RequestMapping("/resp4")
    @ResponseBody
    public List request04() {
        System.out.println("request4");
        List<User> list = new ArrayList<User>();
        list.add(new User(2, "王五", 25, new Book()));
        list.add(new User(2, "李四", 24, new Book()));
        list.add(new User(2, "张三", 23, new Book()));
        return list;
    }


}
